﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CVSA.Suporte.Sinacor.BMFBovespa.Negocio;
using CVSA.Suporte.Sinacor.BMFBovespa.Entidades;
using System.Data;
using System.Data.Odbc;
using System.Configuration;

namespace CVSA.Suporte.Sinacor.BMFBovespa.ConsultaRemedy
{
    public partial class teste : System.Web.UI.Page
    {
        private List<Chamado> chamados = new List<Chamado>();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Request.QueryString["testeOdbc"]))
            {
                string p = string.Empty;
                OdbcConnection cmd = new OdbcConnection("Dsn=AR System ODBC Data Source;arserver=arscorp1;arserverport=50001;UID=" + ConfigurationManager.AppSettings["remedyUserName"] + ";PWD=" + Tools.Decrypt(ConfigurationManager.AppSettings["remedyPassword"], true) + ";aruseunderscores=1;arnamereplace=1;server=NotTheServer");
                OdbcDataAdapter da = new OdbcDataAdapter(p, cmd);
                p = @"SELECT  ""HPD_Help_Desk"".""Submit_Date"", ""HPD_Help_Desk"".""Status"", ""HPD_Help_Desk"".""Assigned_Group"", ""HPD_Help_Desk"".""Assignee"", ""HPD_Help_Desk"".""Incident_Number"", ""HPD_Help_Desk"".""Closed_Date"" ,
                    ""HPD_Help_Desk"".""Configuration_Item"",
                            ""HPD_Help_Desk"".""Last_Resolved_Date"",
                            ""HPD_Help_Desk"".""CATEGORIZATION_TIER_1"",
                            ""HPD_Help_Desk"".""CATEGORIZATION_TIER_2"",
                            ""HPD_Help_Desk"".""CATEGORIZATION_TIER_3"",
                            ""HPD_Help_Desk"".""GENERIC_CATEGORIZATION_TIER_1"",
                            ""HPD_Help_Desk"".""GENERIC_CATEGORIZATION_TIER_2"",
                            ""HPD_Help_Desk"".""GENERIC_CATEGORIZATION_TIER_3"",
                            ""HPD_Help_Desk"".""PRIORITY"",
                            ""HPD_Help_Desk"".""COMPANY"",
                            ""HPD_Help_Desk"".""DESCRIPTION""
                    FROM   ""HPD_Help_Desk"" ""HPD_Help_Desk"" 
                    WHERE  (""HPD_Help_Desk"".""Assigned_Group"" LIKE 'DO-DSE-SUPORTE%') 
                    AND ""HPD_Help_Desk"".""Submit_Date"" > {ts '2009-11-30 00:00:00'}";

                da = new OdbcDataAdapter(p, cmd);
                DataSet dsTotal = new DataSet();
                da.Fill(dsTotal);
                gvTeste.DataSource = dsTotal;
                gvTeste.DataBind();

            }
            else
            {

                Remedy remedy = new Remedy();
                DataTable odt = remedy.ObterDadosOciosos();
                remedy.AtualizarChamadosOciosos(odt);
                //List<Chamado> chamados = new List<Chamado>();
                //chamados = remedy.ObterDados();
                //remedy.Sincronizar(chamados);
            }
        }
    }
}
